package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.AdPosition;
import org.example.pojo.AdPositionVO;

import java.util.List;

@Mapper
public interface AdPositionMapper {

    @Insert("insert into ad_position(create_user, client_id, position_name, position_code, position_type, dimensions, price, state, scheduled_start, scheduled_end, create_time, update_time)" +
            " values (#{createUser}, #{clientId}, #{positionName}, #{positionCode}, #{positionType}, #{dimensions}, #{price}, #{state}, #{scheduledStart}, #{scheduledEnd}, #{createTime}, #{updateTime})")
    void add(AdPosition adPosition);

    @Delete("delete from ad_position where id=#{id}")
    void delete(Integer id);

    List<AdPosition> list(Integer userId, Integer clientId);

    @Update("UPDATE ad_position SET " +
        "client_id=#{clientId}, " +
        "position_name=#{positionName}, " +
        "position_type=#{positionType}, " +
        "dimensions=#{dimensions}, " +
        "price=#{price}, " +
        "state=#{state}, " +
        "scheduled_start=#{scheduledStart}, " +
        "scheduled_end=#{scheduledEnd}, " +
        "update_time=#{updateTime} " +
        "WHERE id=#{id}")
    void update(AdPosition adPosition);

    @Select("select * from ad_position where id=#{id}")
    AdPosition detail(Integer id);

//    @Select("SELECT " +
//            "ap.id AS ad_id, ap.position_name, ap.position_type, ap.dimensions, " +
//            "ap.price, ap.state, ap.scheduled_start, ap.scheduled_end, " +
//            "ap.create_time AS ad_create_time, ap.update_time AS ad_update_time, " +
//            "c.id AS client_id, c.name AS client_name, c.contact_person, c.contact_phone " +
//            "FROM ad_position ap " +
//            "JOIN client c ON ap.client_id = c.id " +
//            "WHERE c.name = #{clientName} and create_user=#{userId}")
//    @Results({
//            @Result(property = "adId", column = "ad_id"),
//            @Result(property = "positionType", column = "position_type"),
//            @Result(property = "state", column = "state"),
//            @Result(property = "scheduledStart", column = "scheduled_start"),
//            @Result(property = "scheduledEnd", column = "scheduled_end"),
//            @Result(property = "adCreateTime", column = "ad_create_time"),
//            @Result(property = "adUpdateTime", column = "ad_update_time"),
//            @Result(property = "clientId", column = "client_id"),
//            @Result(property = "clientName", column = "client_name"),
//            @Result(property = "contactPerson", column = "contact_person"),
//            @Result(property = "contactPhone", column = "contact_phone")
//    })
    List<AdPositionVO> getByClientName(Integer userId, String clientName);
}
